## mako

<%namespace name='static' file='../static_content.html'/>

<%page expression_filter="h"/>

<%!
import json

from django.utils.translation import gettext as _, ngettext
from django.template.defaultfilters import escapejs
from django.urls import reverse

from lms.djangoapps.discussion.django_comment_client.permissions import has_permission
from openedx.core.djangolib.js_utils import dump_js_escaped_json, js_escaped_string
%>

<%block name="js_extra">
<%include file="_js_body_dependencies.html" />
<%static:require_module module_name="discussion/js/discussion_profile_page_factory" class_name="DiscussionProfilePageFactory">
    profile_page_context = {
        'courseSettings': ${course_settings | n, dump_js_escaped_json},
        'courseId': '${str(course.id) | n, js_escaped_string}',
        'courseName': '${course.display_name_with_default | n, js_escaped_string}',
        'contentInfo': ${annotated_content_info | n, dump_js_escaped_json},
        'userInfo': ${user_info | n, dump_js_escaped_json},
        'roles': ${roles | n, dump_js_escaped_json},
        'threads': ${threads | n, dump_js_escaped_json},
        'page': ${page | n, dump_js_escaped_json},
        'sortPreference': '${sort_preference | n, js_escaped_string}',
        'numPages': ${num_pages | n, dump_js_escaped_json}
    }

    DiscussionProfilePageFactory(_.extend(
        {
            el: $('.discussion-user-profile-board')
        },
        profile_page_context
    ));
</%static:require_module>
</%block>

<section class="discussion inline-discussion discussion-user-profile-board page-content-container">
    <header class="page-header">
        <div class="page-header-main">
            <div class="sr-is-focusable" tabindex="-1"></div>
            <div>
                <h2 class="discussion-profile-title">${_("Discussion")}</h2>
                <%def name="span(num)"><span class="discussion-count">${num}</span></%def>
                <span data-hj-suppress class="user-name"><a href="${learner_profile_page_url}">${django_user.username}</a></span>
                <span class="discussion-profile-info">
                    <span class="user-roles">${", ".join(_(role_name) for role_name in django_user_roles)}</span>
                </span>
                <div class="discussion-profile-count">
                    <span class="discussion-profile-info threads-count">${ngettext('%s discussion started', '%s discussions started', profiled_user['threads_count']) % span(profiled_user['threads_count'])}</span>
                    <span class="discussion-profile-info  comments-count">${ngettext('%s comment', '%s comments', profiled_user['comments_count']) % span(profiled_user['comments_count'])}</span>
                </div>
            </div>
        </div>
    </header>
    <div class="page-content">
        <main id="main" aria-label="Content" tabindex="-1" class="discussion-column">
            <div class="course-content discussion-module discussion-user-threads"
                data-course-id="${course.id}"
                data-course-name="${course.display_name_with_default}"
                data-threads="${threads}"
                data-user-info="${user_info}"
                data-user-id="${django_user.id}"
                data-page="${page}"
                data-num-pages="${num_pages}"
                data-user-create-comment="${json.dumps(can_create_comment)}"
                data-user-create-subcomment="${json.dumps(can_create_subcomment)}"
                data-read-only="false"
                data-sort-preference="${sort_preference}"
                data-flag-moderator="${json.dumps(flag_moderator)}"
                data-user-group-id="${user_group_id}">
            </div>
        </main>
    </div>
</section>

<%include file="_underscore_templates.html" />
<%include file="_thread_list_template.html" />
